function modifyCart(user_id, pr_id, nb_item, action) 
{
	var cart = new Array();
	var exists = false;
	
	//alert('User Id: '+ user_id +' Produit Id: '+ pr_id +' Nb item: '+ nb_item +' Action: '+ action);
	
	// If the cart is empty
	if(typeof(localStorage.cart) == "undefined" && action == "add")
	{
		alert('undefined');
		cart['user_id'] = 1;//new Array(user_id);
		cart['pr_id'] = 2;//new Array(pr_id);
		cart['nb_item'] = 3;//new Array(nb_item);
		
		localStorage.cart = JSON.stringify(cart);
		
		alert(cart.join(", "));
	}
	// A cart has already been created
	else if (typeof(localStorage.cart) != "undefined" )
	{
		cart = JSON.parse(localStorage.cart);
		
		// Already defined but empty
		if(cart.length == 0 && action == "add")
		{
			cart['user_id'] = new Array(user_id);
			cart['pr_id'] = new Array(pr_id);
			cart['nb_item'] = new Array(nb_item);
			
			localStorage.cart = JSON.stringify(cart);
		}
		
		// Already defined and not empty
		else
		{
			for (var i = 0; i < cart['pr_id'].length; i++)
			{
				// If the product was already in the user's cart
				if(cart['pr_id'][i] == pr_id && cart['user_id'][i] == user_id)
				{
					if(action == "add")
					{
						cart['nb_item'][i] += nb_item;
					}
					else if (action == "remove")
					{
						//If we are in the last cell of the array
						if(i == cart['pr_id'].length-1)
						{	
							cart['user_id'][i].pop();
							cart['pr_id'][i].pop();
							cart['nb_item'][i].pop();
						}
						
						//The corresponding cell isn't the last cell
						else
						{
							cart['user_id'][i] = cart['user_id'][cart['user_id'].length-1]; 
							cart['pr_id'][i] = cart['pr_id'][cart['pr_id'].length-1]; 
							cart['nb_item'][i] = cart['nb_item'][cart['nb_item'].length-1]; 
							
							cart['user_id'].pop();
							cart['pr_id'].pop();
							cart['nb_item'].pop();					
						}
					}
					else if (action == "subtraction")
					{
						cart['nb_item'][i] -= nb_item;
						
						// If there is no item left for the corresponding product, we remove it from the cart
						if(cart['nb_item'][i] <= 0)
						{
							cart['user_id'][i] = cart['user_id'][cart['user_id'].length-1]; 
							cart['pr_id'][i] = cart['pr_id'][cart['pr_id'].length-1]; 
							cart['nb_item'][i] = cart['nb_item'][cart['nb_item'].length-1];

							cart['user_id'].pop();
							cart['pr_id'].pop();
							cart['nb_item'].pop();	
						}
					} 
					exists = true;
				}
			}
			
			// If the product that the products wants to add do not exists yet, wee just add it
			if(!exists && action == "add")
			{
				cart['user_id'].push(user_id);
				cart['pr_id'].push(pr_id);
				cart['nb_item'].push(nb_item);
			}
			
			localStorage.cart = JSON.stringify(cart);
		}
	}
}

function checkCart(user_id)
{
	var cart = new Array();
	var nbItems = 0;
	
	// If the cart has been initialized 
	if(typeof(localStorage.cart)!= "undefined")
	{
		cart = JSON.parse(localStorage.cart);
		
		// And is not empty
		if(cart.lenght > 0)
		{
			// We browse all the products present in the cart that own to the user
			for (var i = 0; i < cart['pr_id'].length; i++)
			{
				if(cart['user_id'][i] == user_id)
				{
					nbItems += cart['nb_item'][i];
				}
			}
		}
	}
	return nbItems;
}